<?php
class Jobs extends Model{
	function getAll(){
		$sql ="SELECT *,j.id,j.pic,((p.invest + (p.invest * j.ppn / 100) - j.discount) ) as total FROM jobs j ";
		$sql.="LEFT JOIN products p ON p.id=j.product_id ";
		$sql.="LEFT JOIN customers c ON c.id=j.customer_id ";
        /*if(($this->session->userdata('user_pos')== $this->config->item('ta')) || ($this->session->userdata('user_pos')== $this->config->item('se')) ):
            if(($this->session->userdata('user_group')== $this->config->item('user')) && ($this->session->userdata('user_pos')== $this->config->item('ta')) ): 
                $sql.=" WHERE j.pic='".$this->session->userdata('user_id')."'";
            elseif(($this->session->userdata('user_group')== $this->config->item('user')) && ($this->session->userdata('user_pos')== $this->config->item('se')) ): 
                $sql.=" WHERE j.pic='".$this->session->userdata('user_ta')."'";
            endif;
        endif;
		*/
		$sql.=" WHERE j.pic='".$this->session->userdata('user_id')."'";
        $query=$this->db->query($sql);
		return $query->result_array();
	}
    
    function getAllUsers(){
        $sql  =" SELECT * FROM users WHERE pos_id=". $this->config->item('ta') ;
        $sql .=" AND enabled=1 AND sales=1 " ;
        $query=$this->db->query($sql);
		return $query->result_array();
    }
    
    
    function getAllTarget(){
        $sql ="SELECT *,month as month_name FROM jobs_target_head Order by Year DESC,Month DESC ";
        $query=$this->db->query($sql);
		return $query->result_array();
    }
    
    function getAllTargetDetails(){
        $sql =" SELECT *,jtd.id ";
        $sql.=" FROM jobs_target_details jtd";
        
        $sql.=" JOIN users u ON u.username = jtd.username ";
        $sql.=" JOIN user_position p ON p.id = u.pos_id ";
        $query=$this->db->query($sql);
		return $query->result_array();
    }
    
    function getApproval(){
        $sql ="SELECT *,j.pic,j.id,j.no,((p.invest + (p.invest * j.ppn / 100) - j.discount) ) as total FROM jobs j ";
		$sql.="LEFT JOIN products p ON p.id=j.product_id ";
		$sql.="LEFT JOIN customers c ON c.id=j.customer_id ";
        if($this->session->userdata('user_pos')== $this->config->item('spv') ):
            $sql.=" WHERE mgr=0 AND keu=0 ";
        elseif($this->session->userdata('user_pos')== $this->config->item('mgr') ):
            $sql.=" WHERE spv=1 AND keu=0 "; 
        elseif($this->session->userdata('user_pos')== $this->config->item('keu') ):
            $sql.=" WHERE spv=1 AND mgr=1 ";         
        endif;
        $query=$this->db->query($sql);
		return $query->result_array();
    }
    
    function getApprovalByProduction(){
        $sql ="SELECT *,j.id,j.no,j.pic,((p.invest + (p.invest * j.ppn / 100) - j.discount) ) as total FROM jobs j ";
		$sql.="LEFT JOIN products p ON p.id=j.product_id ";
		$sql.="LEFT JOIN customers c ON c.id=j.customer_id ";
        //if($this->session->userdata('user_pos')== $this->config->item('spv') ):
        $sql.=" WHERE mgr=1 AND keu=1 ";
        //elseif($this->session->userdata('user_pos')== $this->config->item('mgr') ):
        $sql.=" AND spv=1 "; 
        //elseif($this->session->userdata('user_pos')== $this->config->item('keu') ):
        $sql.=" ORDER BY date_posting DESC ";         
        //endif;
        $query=$this->db->query($sql);
		return $query->result_array();
    }
	
	function getSearch(){
	    $this->db->select('*,j.pic,((invest + (invest * ppn / 100) - discount) ) as total');
        if($this->input->post('search')):
            if($this->input->post('type_search')<> ""):
                $this->db->where('j.job_type',$this->input->post('type_search'));
            endif;
            
            if($this->input->post('order_search')<> ""):
                $this->db->where('j.order_type',$this->input->post('order_search'));
            endif;
            
            if($this->input->post('incoming_search')<> ""):
                $this->db->where('j.coming_type',$this->input->post('incoming_search'));
            endif;
            
            if($this->input->post('user')<> ""):
                $this->db->where('j.pic',$this->input->post('user'));
            endif;
            
        else:
            $this->db->where('j.id',0);
        endif;
		$query = $this->db->join('products p','p.id=j.product_id','LEFT');
		$query = $this->db->join('customers c','c.id=j.customer_id','LEFT');
        $query = $this->db->get('jobs j');
  
		return $query->result_array();
	}
    
    function getCustomer(){
		$sql ="SELECT * FROM customers c ";
        /*if(($this->session->userdata('user_pos')== $this->config->item('ta')) || ($this->config->item('se') == $this->session->userdata('user_pos')  )  ):
           if(($this->session->userdata('user_group')== $this->config->item('user')) && ($this->session->userdata('user_pos')== $this->config->item('ta')) ):  
                $sql.=" WHERE c.rev='".$this->session->userdata('user_id')."'";
           elseif(($this->session->userdata('user_group')== $this->config->item('user')) && ($this->session->userdata('user_pos')== $this->config->item('se')) ):  
                $sql.=" WHERE c.rev='".$this->session->userdata('user_ta')."'"; 
           endif; 
        endif;*/
		if(($this->session->userdata('user_pos')==$this->config->item('ta'))):
                //$sql.=" AND c.rev='".$this->session->userdata('user_id')."'";
			$sql.=" WHERE c.rev='".$this->session->userdata('user_id')."'";
				//if($this->session->userdata('user_group')<> $this->config->item('admin')):
			$sql.="AND c.spv_approve = 1 ";
				//endif;	
        elseif(($this->session->userdata('user_pos')==$this->config->item('se'))):
                //$sql.=" AND c.rev='".$this->session->userdata('user_ta')."'"; 
			$sql.=" WHERE c.rev2='".$this->session->userdata('user_id')."'";
			$sql.="AND c.spv_approve = 1 ";	
		elseif(($this->session->userdata('user_pos')==$this->config->item('ae'))):	
			$sql.=" WHERE c.rev3='".$this->session->userdata('user_id')."'";
			$sql.="AND c.spv_approve = 1 ";
        endif;
        $query=$this->db->query($sql);
		return $query->result_array();
	}
	
	function getJobFac($id){
		$sql ="SELECT * FROM job_facilitas ";
		$sql.="WHERE job_no='".$id."'";
        $query=$this->db->query($sql);
		return $query->result_array();
	}
    
    function getJobParticipant($id){
		$sql ="SELECT * FROM job_participants ";
		$sql.="WHERE job_id='".$id."'";
        $query=$this->db->query($sql);
		return $query->result_array();
	}
    
    function getCek(){
        $sql ="SELECT * FROM jobs j ";
		$sql.="WHERE no = '".$this->input->post('job_no')."' LIMIT 1";
        $query=$this->db->query($sql);
		return $query->row_array();
    }
    
    function getTargetCek(){
        $sql ="SELECT * FROM jobs_target_head  ";
		$sql.="WHERE month = '".$this->input->post('month')."' AND year = '".$this->input->post('year')."' LIMIT 1";
        $query=$this->db->query($sql);
		return $query->row_array();
    }
    
    function getTargetUserCek(){
        $sql ="SELECT * FROM jobs_target_details  ";
		$sql.="WHERE job_id = ".$this->input->post('id')." AND username = '".$this->input->post('user')."' LIMIT 1";
        $query=$this->db->query($sql);
		return $query->row_array();
    }
    
    function getTargetSave(){
        $value=array(
                        'month'     =>  $this->input->post('month'),
                        'year'      =>  $this->input->post('year'),
                        'status'    =>  1,
                        'user_stamp'=>  $this->session->userdata('user_id'),
                        'date_stamp'=>  date('Y-m-d')  
                        
                    );
       $this->db->insert('jobs_target_head',$value);             
    }
    
    function getTargetUserSave(){
        $value=array(
                        'job_id'    =>  $this->input->post('id'),
                        'target'    =>  $this->input->post('target'),
                        'username'  =>  $this->input->post('user'),
                        'user_stamp'=>  $this->session->userdata('user_id'),
                        'date_stamp'=>  date('Y-m-d')  
                        
                    );
       $this->db->insert('jobs_target_details',$value);             
    }
    
    function getData($id){
		$sql ="SELECT * ,j.id,j.pic,p.invest,((p.invest + (p.invest * j.ppn / 100) - j.discount) ) as total FROM jobs j ";
		$sql.="LEFT JOIN products p ON p.id=j.product_id ";
		$sql.="LEFT JOIN customers c ON c.id=j.customer_id ";
		$sql.="LEFT JOIN banks b ON b.id=j.bank_id ";
        $sql.="WHERE j.id = ".$id." ";
		$query=$this->db->query($sql);
		return $query->row_array();
	}
    
    function getSave(){
		 if($_FILES or $_POST):
			$type = $_FILES['userfile']['type'];
			if($type=='application/pdf')
				$type='pdf';
			elseif($type=='application/doc')
				$type='doc';
			elseif($type=='application/docx')
				$type='docx';		
				
			$config['upload_path'] = './crm-assets/jo/';
			$config['file_name']   = trim($this->input->post('job_no')).'.'.$type;	
			$config['allowed_types'] = 'pdf|doc|docx';
			$config['max_size']	= '900000';
			$this->load->library('upload',$config);
			if (!$this->upload->do_upload())
			{
				echo $config['file_name'];
				$file_name='';
				//$error = array('error' => $this->upload->display_errors());
				//$this->load->view('upload_form', $error);
			}
			else
			{
				$file_name=trim($this->input->post('job_no')).'.'.$type;
				$data = array('upload_data' => $this->upload->data());
				//$this->load->view('upload_success', $data);
			}
		endif;
		
		
		if($this->input->post('ppn')<>""){
			$ppn = 10;
		}else{
			$ppn = 0;
		}
        
        $this->db->select('*');
        $this->db->where('customer_name',$this->input->post('customer'));
        $q=$this->db->get('customers',1);
        $cust=$q->row_array();
        $cust_id=$cust['id'];
		
		if($this->session->userdata('user_group')==$this->config->item('admin')):
			$rev_id =$cust['rev'];
		else:
			$rev_id =$this->session->userdata('user_id');
		endif;
		
        //echo $rev_id;
        
        $sql   = "SELECT id FROM jobs ORDER BY id DESC ";
        $query = $this->db->query($sql);
        $q=$query->row_array();
        $total=$query->num_rows();
        if($total>=1):
            $no=$q['id']+ 1;
        else:
            $no=1;    
        endif;
		
		if($this->input->post('c_product')=='p1'){
			$product = trim($this->input->post('product'));
			$other	 = '';
            $price   = 0;
			$periode = ''; 		
		}
		
		elseif($this->input->post('c_product')=='p2'){
			$this->db->order_by('ABS(id)','DESC');
			$Q=$this->db->get('products',1);
			$data=$Q->row_array();
			$id = $data['id']+1;
			
			$product = $id;
			$other	 = $this->input->post('prod');
            $price   = $this->input->post('price');
			$periode = $this->input->post('periode'); 
			
			$value = array(
							'id'			=>	$id,
							'product_name'	=>	$other,
							'product_time'	=>	$periode,
							'invest'		=>	$price
						  );
			$this->db->insert('products',$value);				
		}
        
        $status['status_id']=$this->config->item('existing');
        $this->db->where('id',trim($cust_id));
        $this->db->update('customers',$status); 
        	
        $value = array  (
                            'id'                =>  $no,
                            'no'                =>  $this->input->post('job_no'),
							'trr'				=>	$file_name,
                            'jo_batch'          =>  $this->input->post('batch'),
                            'customer_id'       =>  trim($cust_id),
                            'pic'               =>  $rev_id,
                            'job_type'          =>  $this->input->post('type'),
                            'order_type'        =>  $this->input->post('order'),
                            'coming_type'       =>  $this->input->post('coming'),
                            'product_id'        =>  $product,
							'other_product'		=>	$other,
							'other_price'		=>	$price,
							'other_periode'		=>	$periode,
                            'bank_id'           =>  trim($this->input->post('bank')),
                            'discount'          =>  $this->input->post('discount'),
                            'ppn'               =>  $ppn,
                            'npwp'              =>  $this->input->post('npwp'),
                            'date_in'           =>  $this->input->post('date_in'),
                            'date_out'          =>  $this->input->post('date_out'),
                            
                            'date_dp'           =>  $this->input->post('date_dp'),
                            'date_payment'      =>  $this->input->post('date_pay'),
                            
                            'human_total'       =>  $this->input->post('tp'),
                            'trainer'           =>  $this->input->post('trainer'),
                            
                            'hour_one'          =>  trim($this->input->post('hr11')).':'.trim($this->input->post('hr12')),
                            'hour_two'          =>  trim($this->input->post('hr21')).':'.trim($this->input->post('hr22')),
                            
                            'sdm_contact'       =>  $this->input->post('sdm_contact'),
                            'sdm_telp'          =>  $this->input->post('sdm_tlp'),
                            //'sdm_hp'            =>  $this->input->post('sdm_hp'),
                            'sdm_fax'           =>  $this->input->post('sdm_fax'),
                            'sdm_pos'           =>  $this->input->post('sdm_pos'),
                            
                            'technic_contact'   =>  $this->input->post('tek_contact'),
                            'technic_telp'      =>  $this->input->post('tek_tlp'),
                            //'technic_hp'        =>  $this->input->post('tek_hp'),
                            'technic_fax'       =>  $this->input->post('tek_fax'),
                            'technic_pos'       =>  $this->input->post('tek_pos'),
                            
                            'acc_contact'       =>  $this->input->post('acc_contact'),
                            'acc_telp'          =>  $this->input->post('acc_tlp'),
                            //'acc_hp'            =>  $this->input->post('acc_hp'),
                            'acc_fax'           =>  $this->input->post('acc_fax'),
                            'acc_pos'           =>  $this->input->post('acc_pos'),
                            
                            'location'          =>  $this->input->post('location'),
                            'date_posting'      =>  date('Y-m-d'),
                            'information'       =>  $this->input->post('information'),
                            'message'           =>  $this->input->post('message'),
                            
                            
                            'user_stamp'=>  $this->session->userdata('user_id'),
                            'date_stamp'=>  date('Y-m-d')
                        );
        $this->db->insert('jobs',$value);
        
        
       	
        $fac=$this->input->post('fac');
        $count=COUNT($fac);
       if($count>=1): 
		//foreach($fac as $ad)
		for($i=0;$i<$count;$i++):
		  if($i<>$count){
				$value2['job_no']       = $no;
				$value2['fac_id']       = $fac[$i];
				$value2['user_stamp']   = $this->session->userdata('user_id');
				$value2['date_stamp']   = date('Y-m-d');
				$this->db->insert('job_facilitas',$value2);
		    }	
        //endforeach;
		endfor;
		endif; 
        
        $p=$this->input->post('p');
        $count=COUNT($p);
       if($count>=1): 
		for($i=0;$i<$count;$i++):
		  if($i<>$count){
				$value3['job_id']       = $no;
				$value3['pos_id']       = $p[$i];
				$this->db->insert('job_participants',$value3);
		    }	
		endfor;
		endif; 
                        
    }
    
    function getUpdate(){
		if($_FILES or $_POST):
			$type = $_FILES['userfile']['type'];
			if($type=='application/pdf')
				$type='pdf';
			elseif($type=='application/doc')
				$type='doc';
			elseif($type=='application/docx')
				$type='docx';		
				
			$config['upload_path'] = './crm-assets/';
			$config['file_name']   = trim($this->input->post('job_no')).'.'.$type;	
			$config['allowed_types'] = 'pdf|doc|docx';
			$config['max_size']	= '9000000';
			$this->load->library('upload',$config);
			if (!$this->upload->do_upload())
			{
				//$file_name='';
				echo $config['upload_path'];
				//$error = array('error' => $this->upload->display_errors());
				//$this->load->view('upload_form', $error);
			}
			else
			{
				$file_name=trim($this->input->post('job_no')).'.'.$type;
				$data = array('upload_data' => $this->upload->data());
				//$this->load->view('upload_success', $data);
			}
		endif;
		
		if($this->input->post('ppn')<>""){
			$ppn = 10;
		}else{
			$ppn = 0;
		}
		
		/*if($this->input->post('c_product')=='p1'){
			$product = trim($this->input->post('product'));
			$other	 = '';
            $price   = 0;
			$periode = ''; 		
		}
		
		elseif($this->input->post('c_product')=='p2'){
			$product =0;
			$other	 = $this->input->post('prod');
            $price   = $this->input->post('price');
			$periode = $this->input->post('periode'); 		
		}
        	*/
        
        $this->db->select('*');
        $this->db->where('customer_name',$this->input->post('customer'));
        $q=$this->db->get('customers',1);
        $cust=$q->row_array();
        $cust_id=$cust['id'];
        
		if($this->session->userdata('user_group')==$this->config->item('admin')):
			$rev_id =$cust['rev'];
		else:
			$rev_id =$this->session->userdata('user_id');
		endif;
		
        $value = array  (
                            'no'                =>  trim($this->input->post('job_no')),
							'trr'				=>	$file_name,
                            'jo_batch'          =>  $this->input->post('batch'),
                            'customer_id'       =>  trim($cust_id),
                            'pic'               =>  $rev_id,
                            'job_type'          =>  $this->input->post('type'),
                            'order_type'        =>  $this->input->post('order'),
                            'coming_type'       =>  $this->input->post('coming'),
                            //'product_id'        =>  $product,
							//'other_product'		=>	$other,
							//'other_price'		=>	$price,
							//'other_periode'		=>	$periode,
                            'bank_id'           =>  trim($this->input->post('bank')),
                            'discount'          =>  $this->input->post('discount'),
                            'ppn'               =>  $ppn,
                            'npwp'              =>  $this->input->post('npwp'),
                            'date_in'           =>  $this->input->post('date_in'),
                            'date_out'          =>  $this->input->post('date_out'),
                            'date_dp'           =>  $this->input->post('date_dp'),
                            'date_payment'      =>  $this->input->post('date_pay'),
                            
                            'human_total'       =>  $this->input->post('tp'),
                            'trainer'           =>  $this->input->post('trainer'),
                            
                            'hour_one'          =>  trim($this->input->post('hr11')).':'.trim($this->input->post('hr12')),
                            'hour_two'          =>  trim($this->input->post('hr21')).':'.trim($this->input->post('hr22')),
                            
                            'sdm_contact'       =>  $this->input->post('sdm_contact'),
                            'sdm_telp'          =>  $this->input->post('sdm_tlp'),
                            //'sdm_hp'            =>  $this->input->post('sdm_hp'),
                            'sdm_fax'           =>  $this->input->post('sdm_fax'),
                            'sdm_pos'           =>  $this->input->post('sdm_pos'),
                            
                            'technic_contact'   =>  $this->input->post('tek_contact'),
                            'technic_telp'      =>  $this->input->post('tek_tlp'),
                            //'technic_hp'        =>  $this->input->post('tek_hp'),
                            'technic_fax'       =>  $this->input->post('tek_fax'),
                            'technic_pos'       =>  $this->input->post('tek_pos'),
                            
                            'acc_contact'       =>  $this->input->post('acc_contact'),
                            'acc_telp'          =>  $this->input->post('acc_tlp'),
                            //'acc_hp'            =>  $this->input->post('acc_hp'),
                            'acc_fax'           =>  $this->input->post('acc_fax'),
                            'acc_pos'           =>  $this->input->post('acc_pos'),
                            
                            'location'          =>  $this->input->post('location'),
                            //'date_posting'      =>  $this->input->post('date'),
                            'information'       =>  $this->input->post('information'),
                            'message'           =>  $this->input->post('message'),
                            
                            'user_stamp'=>  $this->session->userdata('user_id'),
                            'date_stamp'=>  date('Y-m-d')
                        );
        $this->db->where('id',$this->input->post('id'));                 
        $this->db->update('jobs',$value);
        
        $this->db->where('job_no',$this->input->post('id'));
        $this->db->delete('job_facilitas');
        
        $fac=$this->input->post('fac');
        $count=COUNT($fac);
        for($i=0;$i<$count;$i++):
            $value2['job_no']       = $this->input->post('id');
            $value2['fac_id']       = $fac[$i];
            $value2['user_stamp']   = $this->session->userdata('user_id');
            $value2['date_stamp']   = date('Y-m-d');
            $this->db->insert('job_facilitas',$value2);
        endfor;
        
        $this->db->where('job_id',$this->input->post('id'));
        $this->db->delete('job_participants');
        
        $p=$this->input->post('p');
        $count=COUNT($p);
        for($i=0;$i<$count;$i++):
            $value3['job_id']       = $this->input->post('id');
            $value3['pos_id']       = $p[$i];
            $this->db->insert('job_participants',$value3);
        endfor;
                        
    }
    
    function getRemove($id){
        $this->db->where('id',$id);
        $this->db->delete('jobs');
		
        $this->db->where('job_no',$id);
		$Q=$this->db->get('job_facilitas');
		if($Q->num_rows>=1):
			$this->db->where('job_no',$id);
			$this->db->delete('job_facilitas');
		endif;	
    }
    
    function getTargetRemove($id){
        $this->db->where('job_id',$id);
        $this->db->delete('jobs_target_details');
        
        $this->db->where('id',$id);
        $this->db->delete('jobs_target_head');
    }
    
    function getTargetUserRemove($id){
        $this->db->where('id',$id);
        $this->db->delete('jobs_target_details');
        
        /*$this->db->where('job_id',$id);
        $this->db->delete('job_facilitas');*/
    }
    
    function getUpdateApp($pos,$id){
        if($pos==$this->config->item('spv')):
            $value['spv']=1;
            $value['spv_stamp']=$this->session->userdata('user_id');  
        elseif($pos==$this->config->item('mgr')):        
            $value['mgr']=1;
            $value['mgr_stamp']=$this->session->userdata('user_id');
        elseif($pos==$this->config->item('keu')):        
            $value['keu']=1;
            $value['keu_stamp']=$this->session->userdata('user_id');
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelApp($pos,$id){
        if($pos==$this->config->item('spv')):
            $value['spv']=0;
            $value['spv_stamp']=$this->session->userdata('user_id');  
        elseif($pos==$this->config->item('mgr')):        
            $value['mgr']=0;
            $value['mgr_stamp']=$this->session->userdata('user_id');
        elseif($pos==$this->config->item('keu')):        
            $value['keu']=0;
            $value['keu_stamp']=$this->session->userdata('user_id');
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getUpdateAppJM($group,$id){
        if($group==$this->config->item('prod')):
            $value['jo_mom']=1;
            $value['jo_mom_stamp']=$this->session->userdata('user_id');  
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppJM($group,$id){
        if($group==$this->config->item('prod')):
            $value['jo_mom']=0;
            $value['jo_mom_stamp']=$this->session->userdata('user_id');  
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppCD($group,$id){
        if($group==$this->config->item('prod')):
            $value['cd']=1;
            $value['cd_stamp']=$this->session->userdata('user_id');  
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppCD($group,$id){
        if($group==$this->config->item('prod')):
            $value['cd']=0;
            $value['cd_stamp']=$this->session->userdata('user_id');  
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppPL($group,$id){
        if($group==$this->config->item('prod')):
            $value['pl']=1;
            $value['pl_stamp']=$this->session->userdata('user_id');  
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppPL($group,$id){
        if($group==$this->config->item('prod')):
            $value['pl']=0;
            $value['pl_stamp']=$this->session->userdata('user_id');  
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppCI($group,$id){
        if($group==$this->config->item('prod')):
            $value['ci']=1;
            $value['ci_stamp']=$this->session->userdata('user_id');  
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppCI($group,$id){
        if($group==$this->config->item('prod')):
            $value['ci']=0;
            $value['ci_stamp']=$this->session->userdata('user_id');  
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppCITEK($group,$id){
        if($group==$this->config->item('prod')):
            $value['ci_tek']=1;
            $value['ci_tek_stamp']=$this->session->userdata('user_id');  
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppCITEK($group,$id){
        if($group==$this->config->item('prod')):
            $value['ci_tek']=0;
            $value['ci_tek_stamp']=$this->session->userdata('user_id');  
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppPA($group,$id){
        if($group==$this->config->item('prod')):
            $value['pa']=1;
            $value['pa_stamp']=$this->session->userdata('user_id');  
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppPA($group,$id){
        if($group==$this->config->item('prod')):
            $value['pa']=0;
            $value['pa_stamp']=$this->session->userdata('user_id');  
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppPM($group,$id){
        if($group==$this->config->item('prod')):
            $value['pm']=1;
            $value['pm_stamp']=$this->session->userdata('user_id');
		    $this->db->where('id',$id);
            $Q=$this->db->get('jobs',1);
            $rows=$Q->row_array();
            if($rows['job_type']<>'Training'): 			
				$value['pdl']=1;
			else:
				$value['pdl']=0; 
			endif;
            $value['pdl_stamp']=$this->session->userdata('user_id');    
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppPM($group,$id){
        if($group==$this->config->item('prod')):
            $value['pm']=0;
            $value['pm_stamp']=$this->session->userdata('user_id');
            $value['pdl']=0;
            $value['pdl_stamp']=$this->session->userdata('user_id');   
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppPDJ($group,$id){
        if($group==$this->config->item('prod')):
            $value['pm']=1;
            $value['pm_stamp']=$this->session->userdata('user_id');
            $value['pdl']=1;
            $value['pdl_stamp']=$this->session->userdata('user_id');    
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppPDJ($group,$id){
        if($group==$this->config->item('prod')):
            $value['pm']=0;
            $value['pm_stamp']=$this->session->userdata('user_id');
            $value['pdl']=0;
            $value['pdl_stamp']=$this->session->userdata('user_id');   
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppPD($group,$id){
        if($group==$this->config->item('prod')):
            $value['pd']=1;
            $value['pd_stamp']=$this->session->userdata('user_id');
			$this->db->where('id',$id);
			$Q=$this->db->get('jobs',1);
            $rows=$Q->row_array();
            if($rows['job_type']<>'Training'): 			
				$value['pp']=1;
			else:
				$value['pp']=0;
			endif;
			
            //$value['pp']=1;
            $value['pp_stamp']=$this->session->userdata('user_id');    
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppPD($group,$id){
        if($group==$this->config->item('prod')):
            $value['pd']=0;
            $value['pd_stamp']=$this->session->userdata('user_id');
            $value['pp']=0;
            $value['pp_stamp']=$this->session->userdata('user_id');   
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppPP($group,$id){
        if($group==$this->config->item('prod')):
            $value['pd']=1;
            $value['pd_stamp']=$this->session->userdata('user_id');
            $value['pp']=1;
            $value['pp_stamp']=$this->session->userdata('user_id');    
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppPP($group,$id){
        if($group==$this->config->item('prod')):
            $value['pd']=0;
            $value['pd_stamp']=$this->session->userdata('user_id');
            $value['pp']=0;
            $value['pp_stamp']=$this->session->userdata('user_id');   
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppBTR($group,$id){
        if($group==$this->config->item('prod')):
            $value['btr']=1;
            $value['btr_stamp']=$this->session->userdata('user_id');
			$this->db->where('id',$id);
			$Q=$this->db->get('jobs',1);
            $rows=$Q->row_array();
            if($rows['job_type']<>'Training'): 			
				$value['pms']=1;
			else:
				$value['pms']=0;
			endif;
            
            $value['pms_stamp']=$this->session->userdata('user_id');    
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppBTR($group,$id){
        if($group==$this->config->item('prod')):
            $value['btr']=0;
            $value['btr_stamp']=$this->session->userdata('user_id');
            $value['pms']=0;
            $value['pms_stamp']=$this->session->userdata('user_id');   
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppPMS($group,$id){
        if($group==$this->config->item('prod')):
            $value['btr']=1;
            $value['btr_stamp']=$this->session->userdata('user_id');
            $value['pms']=1;
            $value['pms_stamp']=$this->session->userdata('user_id');    
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppPMS($group,$id){
        if($group==$this->config->item('prod')):
            $value['btr']=0;
            $value['btr_stamp']=$this->session->userdata('user_id');
            $value['pms']=0;
            $value['pms_stamp']=$this->session->userdata('user_id');   
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppLK($group,$id){
        if($group==$this->config->item('prod')):
            $value['lk']=1;
            $value['lk_stamp']=$this->session->userdata('user_id');
            $this->db->where('id',$id);
			$Q=$this->db->get('jobs',1);
            $rows=$Q->row_array();
            if($rows['job_type']<>'Training'): 			
				$value['ba_se']=1;
			else:
				$value['ba_se']=0;
			endif;
			
            $value['ba_se_stamp']=$this->session->userdata('user_id');    
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppLK($group,$id){
        if($group==$this->config->item('prod')):
            $value['lk']=0;
            $value['lk_stamp']=$this->session->userdata('user_id');
            $value['ba_se']=0;
            $value['ba_se_stamp']=$this->session->userdata('user_id');   
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppBASE($group,$id){
        if($group==$this->config->item('prod')):
            $value['lk']=1;
            $value['lk_stamp']=$this->session->userdata('user_id');
            $value['ba_se']=1;
            $value['ba_se_stamp']=$this->session->userdata('user_id');    
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppBASE($group,$id){
        if($group==$this->config->item('prod')):
            $value['lk']=0;
            $value['lk_stamp']=$this->session->userdata('user_id');
            $value['ba_se']=0;
            $value['ba_se_stamp']=$this->session->userdata('user_id');   
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppBATRA($group,$id){
        if($group==$this->config->item('prod')):
            $value['ba_tra']=1;
            $value['ba_tra_stamp']=$this->session->userdata('user_id');
            $this->db->where('id',$id);
			$Q=$this->db->get('jobs',1);
            $rows=$Q->row_array();
            if($rows['job_type']<>'Training'): 			
				$value['lap']=1;
			else:
				$value['lap']=0;
			endif;
            $value['lap_stamp']=$this->session->userdata('user_id');    
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppBATRA($group,$id){
        if($group==$this->config->item('prod')):
            $value['ba_tra']=0;
            $value['ba_tra_stamp']=$this->session->userdata('user_id');
            $value['lap']=0;
            $value['lap_stamp']=$this->session->userdata('user_id');   
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppLAP($group,$id){
        if($group==$this->config->item('prod')):
            $value['ba_tra']=1;
            $value['ba_tra_stamp']=$this->session->userdata('user_id');
            $value['lap']=1;
            $value['lap_stamp']=$this->session->userdata('user_id');    
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppLAP($group,$id){
        if($group==$this->config->item('prod')):
            $value['ba_tra']=0;
            $value['ba_tra_stamp']=$this->session->userdata('user_id');
            $value['lap']=0;
            $value['lap_stamp']=$this->session->userdata('user_id');   
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppLLP($group,$id){
        if($group==$this->config->item('prod')):
            $value['llp']=1;
            $value['llp_stamp']=$this->session->userdata('user_id');
			$this->db->where('id',$id);
			$Q=$this->db->get('jobs',1);
            $rows=$Q->row_array();
            if($rows['job_type']<>'Training'): 			
				$value['ba2_se']=1;
			else:
				$value['ba2_se']=0;
			endif;
            
            $value['ba2_se_stamp']=$this->session->userdata('user_id');    
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppLLP($group,$id){
        if($group==$this->config->item('prod')):
            $value['llp']=0;
            $value['llp_stamp']=$this->session->userdata('user_id');
            
			$value['ba2_se']=0;
            $value['ba2_se_stamp']=$this->session->userdata('user_id');   
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
    
    function getUpdateAppBA2SE($group,$id){
        if($group==$this->config->item('prod')):
            $value['llp']=1;
            $value['llp_stamp']=$this->session->userdata('user_id');
            $value['ba2_se']=1;
            $value['ba2_se_stamp']=$this->session->userdata('user_id');    
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);        
    }
    
    function getCancelAppBA2SE($group,$id){
        if($group==$this->config->item('prod')):
            $value['llp']=0;
            $value['llp_stamp']=$this->session->userdata('user_id');
            $value['ba2_se']=0;
            $value['ba2_se_stamp']=$this->session->userdata('user_id');   
        endif;
        
        $this->db->where('id',$id);
        $this->db->update('jobs',$value);          
    }
}